<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button onclick="fn()">停止定时器</button>
  <script>
    // 3秒之后执行一次
    var timer = setTimeout(function () {
      console.log(123)
    }, 3000)

    function fn () {
      clearTimeout(timer)
    }

  </script>
</body>
</html>